package com.atguigu.dga.governance.assess.calc;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.atguigu.dga.governance.assess.Assessor;
import com.atguigu.dga.governance.bean.AssessParam;
import com.atguigu.dga.governance.bean.GovernanceAssessDetail;
import com.atguigu.dga.meta.bean.TableMetaInfo;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;


@Component("NO_PRODUCE")
public class NoProduceAssessor extends Assessor {
    @Override
    public void checkProblem(GovernanceAssessDetail governanceAssessDetail, AssessParam assessParam) throws ParseException {
        TableMetaInfo tableMetaInfo = assessParam.getTableMetaInfo();

        Date tableLastModifyTime = tableMetaInfo.getTableLastModifyTime();
        //如果 表的最后修改日期+参数天数 < 当前时间 那么 给差评
        String metricParamsJson = assessParam.getGovernanceMetric().getMetricParamsJson();
        JSONObject paramJsonObj = JSON.parseObject(metricParamsJson);
        Integer days = paramJsonObj.getInteger("days");

        String assessDate = assessParam.getAssessDate();
        Date assessDateDt = DateUtils.parseDate(assessDate, "yyyy-MM-dd");

        Date limitDate = DateUtils.addDays(tableLastModifyTime, days);

        if(limitDate.compareTo(assessDateDt) <0 ){  // 前小后大 给差评
            governanceAssessDetail.setAssessScore(BigDecimal.ZERO);
            governanceAssessDetail.setAssessProblem("长期没有数据产出");
            governanceAssessDetail.setAssessComment("最后产出时间："+tableLastModifyTime );
        }


    }


}
